package final2107.night.day02;

public class CharCountDemo {
    public static void main(String[] args) {
        String str = "AAAAAABBBCCCCCDDDBDDDD";
        //将字符串转换为字符数组
        char[] ary = str.toCharArray();
        //定义计数器，初始值为1
        int count = 1;
        //定义StringBuilder保存字符及次数
        StringBuilder builder = new StringBuilder();
        //遍历字符数组
        for (int i=0;i<ary.length-1;i++){
            //拿后一位与当前为比较是否相等
            if (ary[i]==ary[i+1]){
                count++;
            }else {
                builder.append(ary[i]).append(count);
                count = 1;
            }
        }
        builder.append(ary[ary.length-1]).append(count);
        System.out.println(builder.toString());
    }
}
